import sys,os,time

# sys.argv[1] # start.bat
from my import *


import pyperclip as pc
def func(isHelp=False):
    if(isHelp):
        return ["autopip",   "~ autopip <.py>  =pip install unknown module"]
    exec(getFileCode("D:/MYPATH/__tools__/else/getArgv.py"))
    argv = getArgv()
    print(argv)
    cmdStream=os.popen(" ".join(argv[1:]))
    stdOutput="".join(cmdStream.readlines())
    print(stdOutput)
    targetTag = 'No module named \''

    tagIndex = stdOutput.find(targetTag)
    if(tagIndex>=0):
        time.sleep(2)
        moduleIndex = tagIndex + len(targetTag)
        moduleEndIndex = stdOutput[moduleIndex:].find("'")
        moduleName = stdOutput[moduleIndex:moduleEndIndex]
        print(moduleName)
        time.sleep(2)
        os.system("pip install "+moduleName)
        print(" ".join(sys.argv))
        os.system(" ".join(sys.argv))
